package com.five.wisdomEat.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.IdUtil;
import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.entity.RestaurantOrders;
import com.five.wisdomEat.service.RestaurantOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/restaurantorders")
public class RestaurantOrdersController {
    @Autowired
    private RestaurantOrdersService service;

    @GetMapping("/getRorderListByBusiness")
    public ResponseMessage selectROrderListByBusiness(String bNumber){
        return service.selectROrderListByBusiness(bNumber);
    }

    @GetMapping("/getRorderListByStudent")
    public ResponseMessage selectROrderListByStudent(String sNumber){
        return service.selectROrderListByStudent(sNumber);
    }

    @PostMapping("/insertROrder")
    public ResponseMessage insertROrder(String roContent, Integer roCount,Double roPrice,
                                        Integer roPaymentId,Integer roStateId,String roSNumber,String roBNumber){
        RestaurantOrders restaurantOrders = new RestaurantOrders();
        restaurantOrders.setRoNumber(IdUtil.fastSimpleUUID());
        restaurantOrders.setRoContent(roContent);
        restaurantOrders.setRoCount(roCount);
        restaurantOrders.setRoPrice(roPrice);
        restaurantOrders.setRoPaymentId(roPaymentId);
        restaurantOrders.setRoStateId(roStateId);
        restaurantOrders.setRoSNumber(roSNumber);
        restaurantOrders.setRoBNumber(roBNumber);
        restaurantOrders.setRoBuyTime(new DateTime());
        return service.insertROrder(restaurantOrders);
    }

    @PostMapping("/updateROrder")
    public ResponseMessage updateROrder(String roNumber,Integer roStateId){
        RestaurantOrders restaurantOrders = new RestaurantOrders();
        restaurantOrders.setRoNumber(roNumber);
        restaurantOrders.setRoStateId(roStateId);
        return service.updateROrder(restaurantOrders);
    }

    @PostMapping("/deleteROrder")
    public ResponseMessage deleteROrder(String roNumber){
        return service.deleteROrder(roNumber);
    }

    @GetMapping("/getRorderListByBusinessExample")
    public ResponseMessage selectROrderListByBusinessExample(String roBNumber,String roNumber,String sName,Integer roStateId,Integer roPaymentId){
        RestaurantOrders restaurantOrders = new RestaurantOrders();
        restaurantOrders.setRoBNumber(roBNumber);
        restaurantOrders.setRoNumber(roNumber);
        restaurantOrders.setSName(sName);
        restaurantOrders.setRoStateId(roStateId);
        restaurantOrders.setRoPaymentId(roPaymentId);
        return service.selectROrderListByBusinessExample(restaurantOrders);
    }

    @GetMapping("/getRorderListByStudentExample")
    public ResponseMessage selectROrderListByStudentExample(String roSNumber,String roNumber,String bName,Integer roStateId,Integer roPaymentId){
        RestaurantOrders restaurantOrders = new RestaurantOrders();
        restaurantOrders.setRoSNumber(roSNumber);
        restaurantOrders.setRoNumber(roNumber);
        restaurantOrders.setBName(bName);
        restaurantOrders.setRoStateId(roStateId);
        restaurantOrders.setRoPaymentId(roPaymentId);
        return service.selectROrderListByStudentExample(restaurantOrders);
    }

    @GetMapping("/selectOrdersCount")
    public ResponseMessage selectOrdersCount(){
        return service.selectOrdersCount();
    }

    @PostMapping("/confirmROrder")
    public ResponseMessage confirmROrder(String roNumber){
        return service.confirmROrder(roNumber);
    }

    @PostMapping("/saleROrder")
    public ResponseMessage saleROrder(String roNumber){
        return service.saleROrder(roNumber);
    }
}
